class InvitationsController < ApplicationController

  # GET /invitations/new
  # GET /invitations/new.xml
  def new
    @invitation = Invitation.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @invitation }
    end
  end


  # POST /invitations
  # POST /invitations.xml
  def create
    @invitation = Invitation.new(params[:invitation])
    @invitation.talk_id = session[:talk_id]
    @talk = Talk.find(session[:talk_id])
    respond_to do |format|
      if @invitation.save
        Mailer.deliver_invitation(@invitation)
        flash[:notice] = 'Thank you, invitation sent!'
        format.html { redirect_to(@talk) }
        format.xml  { render :xml => @invitation, :status => :created, :location => @invitation }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @invitation.errors, :status => :unprocessable_entity }
      end
    end
  end

end
